package com.jingdianjichi.oss.config;


import com.jingdianjichi.oss.adapter.StorageAdapter;

import com.jingdianjichi.oss.adapter.AilStorageAdapter;
import com.jingdianjichi.oss.adapter.MinioStorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RefreshScope//刷类，
public class StorageConfig {

    @Value("${storage.service.type}")
    private String storageType;


    @Bean
   @RefreshScope//只要storageType的值有更改，nacos会通知我们，如果有这个注解，它就会刷bean
    public StorageAdapter storageService(){

        if("minio".equals(storageType)){
            return new MinioStorageAdapter();
        }
       else if("aliyun".equals(storageType)){
            return new AilStorageAdapter();
        }
       else {
           throw new IllegalArgumentException("未找到相应的文件存储处理器");
        }

    }


}
